let gulp = require('gulp'),
    connect = require('gulp-connect'),
    less = require('gulp-less'),
    watch = require('gulp-watch');

gulp.task('js', function () {
    gulp.src('src/**/*.js')
        .pipe(gulp.dest('dist'))
        .pipe(connect.reload())
})

gulp.task('html', function () {
    gulp.src('src/*.html')
        .pipe(gulp.dest('dist'))
        .pipe(connect.reload())
})

gulp.task('less', function () {
    gulp.src('src/**/*.less')
        .pipe(less())
        .pipe(gulp.dest('dist'))
        .pipe(connect.reload())
})

gulp.task('server', function() {
    connect.server({
        root: "./dist",
        livereload: true,
        port: 8030
    })
})

gulp.task('watch', function() {
    watch("src/*.html", gulp.parallel('html',function() {
        console.log('html 拷贝成功')
    }));
    watch("src/**/*.js", gulp.parallel('js',function() {
        console.log('js压缩成功')
    }));
    watch("src/less/*.less",gulp.parallel('less',function() {
        console.log('less编译成功')
    }));
})


gulp.task('default',gulp.parallel('watch','server',function() {
    console.log('操作成功')
}))
